package com.bjfu.intelligentrecognizeserver.question_answer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    private final IntelligentRecognitionServer intelligentRecognitionServer;

    @Autowired
    public WebSocketConfig(IntelligentRecognitionServer webSocketHandler) {
        this.intelligentRecognitionServer = webSocketHandler;
    }
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        //注册端点，并允许所有跨域请求
        registry.addHandler(intelligentRecognitionServer,"/questionAnswer/{userId}").setAllowedOrigins("*");
    }
}
